<template>
  <div class="equipment-container">
    <vab-query-form>
      <vab-query-form-left-panel :span="24" style="margin-bottom: 20px">
        <el-form :inline="true" :model="queryForm" @submit.native.prevent>
          <el-form-item label="用户名:">
            <el-input
              v-model.trim="queryForm.userName"
              placeholder="用户名"
              clearable
              @keyup.enter.native="queryData()"
            />
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" @click="queryData">
              查询
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-left-panel>
    </vab-query-form>
	
	<el-table
      v-loading="listLoading"
      :data="list"
      height="520"
      border
      stripe
      :element-loading-text="elementLoadingText"
      @selection-change="setSelectRows"
    >
      <el-table-column
        width="260"
        show-overflow-tooltip
        prop="userName"
        fixed="left"
        label="用户名称"
      ></el-table-column>
	  <el-table-column
        width="130"
        show-overflow-tooltip
        prop="userId"
        fixed="left"
        label="用户ID"
      ></el-table-column>
	  <el-table-column
	    width="130"
	    show-overflow-tooltip
	    prop="phoneNumber"
	    fixed="left"
	    label="手机号码"
	  ></el-table-column>
     <el-table-column
       width="180"
       show-overflow-tooltip
       prop="openId"
       fixed="left"
       label="OPENID"
     ></el-table-column>
	  <el-table-column
	    show-overflow-tooltip
	    prop="updateTime"
	    width="180"
	    label="创建日期"
	  ></el-table-column>
	  <el-table-column show-overflow-tooltip label="操作" width="150">
	    <template #default="{ row }">
	      <el-button
	        v-permissions="['admin', 'staff']"
	        icon="el-icon-delete"
	        type="danger"
	        @click="handleDelete(row)"
	      >
	        删除
	      </el-button>
	    </template>
	  </el-table-column>
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNo"
      :page-size="queryForm.pageSize"
      :layout="layout"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    ></el-pagination>
  </div>
</template>

<script>

import { getList,doDelete } from '@/api/openid'

export default {
  name: 'UserOpenIdList',
  components: {},
  data() {
    return {
      list: null,
      listLoading: true,
      layout: 'total, sizes, prev, pager, next, jumper',
      total: 0,
      selectRows: '',
      elementLoadingText: '正在加载...',
      queryForm: {
        pageNo: 1,
        pageSize: 50,
		userName: ''
      },
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    setSelectRows(val) {
      this.selectRows = val
    },
    
    handleSizeChange(val) {
      this.queryForm.pageSize = val
      this.fetchData()
    },
    handleCurrentChange(val) {
      this.queryForm.pageNo = val
      this.fetchData()
    },
	handleDelete(row) {
	  if (row.id) {
	    this.$baseConfirm('你确定要删除当前OPENID吗', null, async () => {
	      await doDelete(row.openId)
	      this.$baseMessage('OPENID删除成功', 'success')
	      this.fetchData()
	    })
	  }
	},
    queryData() {
      this.queryForm.pageNo = 1
      this.fetchData()
    },
    async fetchData() {
      this.listLoading = true
      const { records, totalElement } = await getList(this.queryForm)

      this.list = records
      this.total = totalElement
      setTimeout(() => {
        this.listLoading = false
      }, 300)
    },
  },
}
</script>
<style lang="scss" scoped>
.el-row {
  &:last-child {
    margin-bottom: 20px;
  }
}
.el-table__body {
  .el-link:last-child {
    margin-left: 10px;
  }
}

::v-deep {
  .el-select {
    width: 100%;
  }
}
</style>
